home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / sqlite.class.php < prev    next >
Encoding:
PHP Script  |  2006-04-18  |  1.3 KB  |  68 lines

  1. <?php
  2.  
  3. class sqlite {
  4.     
  5.     var $dbPath;
  6.     
  7.     var $connId;
  8.     
  9.     var $error;
  10.     
  11.     var $errorMessage;
  12.     
  13.     var $readOnly;
  14.     
  15.     var $resId;
  16.     
  17.     var $dbVersion;
  18.     
  19.     function sqlite($dbPath) {
  20.         $this->dbPath = $dbPath;
  21.         
  22.     }
  23.     
  24.     function isReadOnly() {
  25.         return $this->readOnly;
  26.     }
  27.     
  28.     function getVersion() {
  29.         return $this->dbVersion;
  30.     }
  31.     
  32.    function getConnId() {
  33.         if(is_resource($this->connId) || is_object($this->connId)) {
  34.             return $this->connId;
  35.         } else {
  36.             return false;
  37.         }
  38.     } 
  39.     
  40.     function escape($string) {
  41.         if(function_exists('sqlite_escape_string')) {
  42.             $res = sqlite_escape_string($string);
  43.         } else {
  44.             $res = str_replace("'", "''", $string);
  45.         }
  46.         return $res;
  47.     }    
  48.  
  49.     /**
  50.      * Get version number of SQLite database file
  51.      *
  52.      * @param string $fullPath full path with filename of the database file
  53.      * @return version number or false
  54.      */
  55.     function getDbVersion($fullPath){
  56.         if(!file_exists($fullPath)) $fullPath = DEFAULT_DB_PATH . $fullPath;
  57.         $fp = @fopen($fullPath, 'r');
  58.         if ($fp){
  59.             $signature = fread($fp, 47);
  60.             if($signature == "** This file contains an SQLite 2.1 database **") $dbVersion = 2;
  61.             elseif(substr($signature, 0, 15) == "SQLite format 3") $dbVersion = 3;
  62.             else $dbVersion = false;
  63.             fclose($fp);
  64.             return $dbVersion;
  65.         }
  66.     }   
  67. }
  68. ?>